package com.wss.common.base;

import butterknife.BindComponent;
import com.wss.common.adapter.FragmentPagerAdapter;
import com.wss.common.base.mvp.BasePresenter;
import com.wss.common.bean.HorizontalTabTitle;
import com.wss.common.widget.PagerSlidingTabStrip;
import ohos.aafwk.content.Intent;
import ohos.agp.components.PageSlider;
import java.util.List;

public abstract class BaseHorizontalTabAbility<P extends BasePresenter> extends BaseActionBarAbility<P> {

//    @BindComponent(ResourceTable.Id_pst_tab)
    PagerSlidingTabStrip tabStrip;

//    @BindComponent(ResourceTable.Id_vp_list)
    PageSlider viewPager;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_horizontal_tab;
    }


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        initView();
    }

    protected void initView() {

        tabStrip = (PagerSlidingTabStrip) findComponentById(ResourceTable.Id_pst_tab);
        viewPager = (PageSlider) findComponentById(ResourceTable.Id_vp_list);

        viewPager.setProvider(new FragmentPagerAdapter(getTabTitles()) {
            @Override
            public BaseFragment getTabFragment() {
                return BaseHorizontalTabAbility.this.getTabFragment();
            }
        });
        tabStrip.setViewPager(viewPager);
    }

    /**
     * 选项卡List
     *
     * @return List<HorizontalTabTitle>
     */
    protected abstract List<HorizontalTabTitle> getTabTitles();

    /**
     * 滑动Fragment
     *
     * @return BaseFragment
     */
    protected abstract BaseFragment getTabFragment();
}
